package com.macro.mall.tiny.modules.oms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.oms.model.OmsGood;
import com.macro.mall.tiny.modules.oms.service.OmsGoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * vip计划表 前端控制器
 * </p>
 *
 * @author tyrone
 * @since 2024-10-25
 */
@RestController
@RequestMapping("/oms/omsVipPlan")
@Api(tags = "OmsVipPlanController", description = "VIP计划管理")
@Tag(name = "OmsVipPlanController", description = "VIP计划管理")
public class OmsVipPlanController {

    @Autowired
    private OmsGoodService omsGoodService;

    @ApiOperation(value = "获取所有VIP计划")
    @GetMapping()
    public CommonResult<List<OmsGood>> list() {
        return CommonResult.success(omsGoodService.list());
    }

    @ApiOperation(value = "后台分页获取VIP计划")
    @PostMapping("/page")
    public CommonResult<Page<OmsGood>> page(@RequestBody OmsGood omsGood) {
        QueryWrapper<OmsGood> query = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(omsGood.getName())){
            query.like("name", omsGood.getName());
        }
        if(omsGood.getId() != null){
            query.eq("id", omsGood.getId());
        }
        return CommonResult.success(omsGoodService.page(new Page<>(omsGood.getPageNum(),omsGood.getPageSize(),Boolean.TRUE),query));
    }

    @ApiOperation(value = "修改VIP计划")
    @PutMapping()
    public CommonResult<Boolean> update(@RequestBody OmsGood omsGood) {
        return CommonResult.success(omsGoodService.updateById(omsGood));
    }

    @ApiOperation(value = "添加VIP计划")
    @PostMapping()
    public CommonResult<Boolean> add(@RequestBody OmsGood omsGood) {
        return CommonResult.success(omsGoodService.save(omsGood));
    }

    @ApiOperation(value = "批量删除VIP计划")
    @DeleteMapping()
    public CommonResult<Boolean> delete(@RequestParam List<Integer> ids) {
        return CommonResult.success(omsGoodService.removeByIds(ids));
    }


}

